package com.dsg.controller;

import com.dsg.entity.Customer;
import com.dsg.entity.Customertype;
import com.dsg.entity.Fenpeistart;
import com.dsg.entity.Kehustart;
import com.dsg.service.CustomerService;
import com.dsg.service.FenpeistartService;
import com.dsg.utils.Log;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
@Controller
@RequestMapping("cus/hkzygl")
public class FenpeistartController {
       private  String msg;

        @Resource
        private CustomerService customerService;
        @Resource
        private FenpeistartService fenpeistartService;
        @GetMapping("/list")
        @ResponseBody
        public List<Fenpeistart> list(){
            return fenpeistartService.searchAll();
        }

        @GetMapping("/queryAll")
        @ResponseBody
        public List<Kehustart> queryAll(){
            return customerService.seachAllType();
        }
        @GetMapping("/queryleixing")
        @ResponseBody
        public List<Customertype> queryleixing(){
            return customerService.seachleixing();
        }

    @GetMapping("/update")
    @ResponseBody
    public String update(Customer customer){
        try{
            int i = customerService.update(customer);
            if(i>0){
                msg="修改成功！";
            }else{
                msg="修改失败。。。";
            }

        }catch (Exception ex){
            msg="修改失败！";
        }
        return msg;
    }
    @PostMapping("/add")
    @ResponseBody
    public  String add(Customer customer){
          try{
              customerService.add(customer);
              msg="添加成功！";
          }catch (Exception ex){
              msg="添加失败！";
              Log.logger.error(msg,ex);
          }
        return msg;
    }
}
